﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace MasApp.BLL
{
    public class Delete
    {
        public Delete()
        {
            //
            //TODO: 在此处添加构造函数逻辑
            //
        }
        public static bool DeleteWeightMission(Model.weightmission wm)
        {
            string s = "Delete From weightmission Where projectid = " + wm.Projectid
                + " And actor='" + wm.Actor + "' And weightmissiontype = '" + wm.Weightmissiontype + "'"
                + " And state = '未做的'";
            return DAL.Delete.ExecuteNonQuery(s) == 1 ? true : false;
        }
        /// <summary>
        /// 通过model.levelmission 删除评级专家，包括评级任务，对应的用户角色
        /// </summary>
        /// <param name="lm">lm.Actorroleid + lm.Projectid + lm.Actor</param>
        /// <returns></returns>
        public static int DeleteLevelExper(Model.levelmission lm)
        {
            if (MasApp.DAL.Search.HaveUserInLevelMission(lm) > 0)
            {
                MasApp.DAL.Delete.DeleteUserroleByUrid(lm.Actorroleid);
                MasApp.DAL.Delete.DeleteLevelMission(lm);
                return 1;
            }
            else
            {
                return 0;
            }
        }
        /// <summary>
        /// 通过用户名设置登录为false
        /// </summary>
        /// <param name="username"></param>
        /// <returns></returns>
        public static bool SetLoginFalse(string username)
        {
            return MasApp.DAL.Delete.SetLoginFalse(username);
        }
        /// <summary>
        /// 通过用户名删除组织用户登录
        /// </summary>
        /// <param name="username"></param>
        /// <returns></returns>
        public static bool DeleteOrgLogin(string username)
        {
            return MasApp.DAL.Delete.DeleteOrgLogin(username);
        }
        /// <summary>
        /// 删除特定的管理员账号
        /// </summary>
        /// <param name="username"></param>
        /// <returns></returns>
        public static bool DelManaUser(string username)
        {
            int userid = MasApp.DAL.Search.SearchUserID(username);
            if (DeleteLogin(username) && DeleteUser(username) && DeleteUserrole(userid))
                return true;
            else
                return false;
        }
        /// <summary>
        /// 删除用户信息
        /// </summary>
        /// <param name="username"></param>
        /// <returns></returns>
        public static bool DeleteUser(string username)
        {
            return MasApp.DAL.Delete.DeleteUser(username);
        }
        /// <summary>
        /// 删除登录信息
        /// </summary>
        /// <param name="username"></param>
        /// <returns></returns>
        public static bool DeleteLogin(string username)
        {
            return MasApp.DAL.Delete.DeleteLogin(username);
        }
        /// <summary>
        /// 删除用户的用户角色
        /// </summary>
        /// <param name="userid"></param>
        /// <returns></returns>
        public static bool DeleteUserrole(int userid)
        {
            return MasApp.DAL.Delete.DeleteUserrole(userid);
        }

        public static bool DeleteProject(int projectid)
        {
            return MasApp.DAL.Delete.DeleteProject(projectid) > 0 ? true : false;
        }

        public static bool DeleteModelAll(int modelid)
        {
            DataSet ds_ruleid = Search.SearchRuleID(modelid);
            if (ds_ruleid.Tables[0].Rows.Count > 0)
            {
                for (int i = 0; i < ds_ruleid.Tables[0].Rows.Count; i++)
                {
                    if (!DAL.Delete.DeleteIndicator(Convert.ToInt32(ds_ruleid.Tables[0].Rows[i][0])))
                    {
                        return false;
                    }
                }
                if (DAL.Delete.DeleteRule(modelid))
                {
                }
                else
                {
                    return false;
                }
            }
            if (DAL.Delete.DeleteModel(modelid))
            {
                return true;
            }
            else
            {
                return false;
            }
        }
        /// <summary>
        /// 删除方法及方法下的等级
        /// </summary>
        /// <param name="methodid"></param>
        /// <returns></returns>
        public static bool DeleteMethodAll(int methodid)
        {
            bool i = MasApp.DAL.Delete.DeleteLevel(methodid);
            bool j = MasApp.DAL.Delete.DeleteMethod(methodid);
            if ( j)
                return j;
            else
                return false;
        }
    }
}